﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Streambolics.Hp41s
{
    public class AlphaKeyboardMapping : KeyboardMapping
    {
        private Dictionary<int, string> _Characters = new Dictionary<int, string> ();

        public AlphaKeyboardMapping (bool aShifted)
            : base (aShifted)
        {
        }

        public void AssignChars (int aKey, string aString)
        {
            if (_Characters.ContainsKey (aKey))
            {
                _Characters.Remove (aKey);
            }
            _Characters.Add (aKey, aString);
        }

        public void AssignChars (int aKey, params string[] aStrings)
        {
            foreach (string s in aStrings)
            {
                AssignChars (aKey++, s);
            }
        }

        public override InstructionFactory Assigned (int aKey, Context aContext)
        {
            if (_Characters.ContainsKey (aKey))
            {
                return new AlphaInstructionFactory (_Characters[aKey]);
            }
            else
            {
                return base.Assigned (aKey, aContext);
            }
        }
    }
}
